﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace IceDog.DNL.CSharp.Grammar.Diagnostics
{
    public static class DiagnosticHelper
    {
        /// <summary>
        /// 无返回无输入的时间判断
        /// </summary>
        /// <param name="action"></param>
        /// <returns>返回结果字符串</returns>
        public static string Run(Action action)
        {
            Stopwatch watch = Stopwatch.StartNew();
            action();
            watch.Stop();
            long ms = watch.ElapsedMilliseconds;
            var result = $"\n花费时间：{ms}ms\n";
            return result;
        }
        /// <summary>
        /// 有一个输入的时间判断
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="action"></param>
        /// <param name="value"></param>
        /// <returns>返回结果字符串</returns>
        public static string Run<T>(Action<T> action, T value)
        {
            Stopwatch watch = Stopwatch.StartNew();
            action(value);
            watch.Stop();
            long ms = watch.ElapsedMilliseconds;
            var result = $"\n花费时间：{ms}ms\n";
            return result;
        }
    }
}
